package com.my.study.bean;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author: yidujun
 * @create: 2021/03/23 16:14
 */
public class UserEditor extends PropertyEditorSupport {

    public static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        String[] tokens = text.split("\\|");
        User user = new User();
        user.setName(tokens[0]);
        user.setEmail(tokens[1]);
        try{
            user.setDate(SDF.parse(tokens[2]));
        }catch(ParseException e){
            throw new IllegalArgumentException(e);
        }
        setValue(user);
    }
}
